package cn.com.mr01.lianxi.mr_lianxi_09;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class TokenizerMapper extends
		Mapper<LongWritable, Text, Text, IntWritable> {

	Text k = new Text();
	IntWritable n = new IntWritable(1);

	/**
	 * map 中的值设置成<"1001 \t 2001",1>
	 */
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {

		// 1. 切分
		String[] words = value.toString().split("\t");

		// 设置输出的 key
		// 例如 : <"1001 \t 2001",1>
		k.set(words[0] + "\t" + words[3]);
		context.write(k, n);
	}
}
